home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / CIncludes / fenv.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-12  |  11.4 KB  |  300 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        fenv.h
  3.  
  4.      Contains:    Floating-Point environment for PowerPC and 68K
  5.  
  6.      Version:    Technology:    MathLib v2
  7.                  Release:    Universal Interfaces 3.0.1
  8.  
  9.      Copyright:    © 1987-1997 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __FENV__
  19. #define __FENV__
  20.  
  21. #ifndef __CONDITIONALMACROS__
  22. #include <ConditionalMacros.h>
  23. #endif
  24.  
  25.  
  26.  
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if PRAGMA_IMPORT
  36. #pragma import on
  37. #endif
  38.  
  39. #if PRAGMA_STRUCT_ALIGN
  40.     #pragma options align=mac68k
  41. #elif PRAGMA_STRUCT_PACKPUSH
  42.     #pragma pack(push, 2)
  43. #elif PRAGMA_STRUCT_PACK
  44.     #pragma pack(2)
  45. #endif
  46.  
  47. /*
  48.         A collection of functions designed to provide access to the floating
  49.         point environment for numerical programming. It is modeled after
  50.         the floating-point requirements in C9X.
  51.         
  52.         The file <fenv.h> declares many functions in support of numerical
  53.         programming.  It provides a set of environmental controls similar to
  54.         the ones found in <SANE.h>.  Programs that test flags or run under
  55.         non-default modes must do so under the effect of an enabling
  56.         "fenv_access" pragma.
  57. */
  58.  
  59. #if TARGET_CPU_PPC
  60. /*    The typedef fenv_t is a type for representing the entire floating-point
  61.       environment in a single object.                                         */
  62. typedef long                             fenv_t;
  63. /*    The typedef fexcept_t is a type for representing the floating-point
  64.       exception flag state collectively.                                      */
  65. typedef long                             fexcept_t;
  66. /*    Definitions of floating-point exception macros                          */
  67.  
  68. enum {
  69.     FE_INEXACT                    = 0x02000000,
  70.     FE_DIVBYZERO                = 0x04000000,
  71.     FE_UNDERFLOW                = 0x08000000,
  72.     FE_OVERFLOW                    = 0x10000000,
  73.     FE_INVALID                    = 0x20000000
  74. };
  75.  
  76. /*    Definitions of rounding direction macros                                */
  77.  
  78. enum {
  79.     FE_TONEAREST                = 0x00000000,
  80.     FE_TOWARDZERO                = 0x00000001,
  81.     FE_UPWARD                    = 0x00000002,
  82.     FE_DOWNWARD                    = 0x00000003
  83. };
  84.  
  85. #endif  /* TARGET_CPU_PPC */
  86.  
  87. #if TARGET_CPU_68K
  88. #if TARGET_RT_MAC_68881
  89. typedef long                             fexcept_t;
  90. struct fenv_t {
  91.     long                             FPCR;
  92.     long                             FPSR;
  93. };
  94. typedef struct fenv_t fenv_t;
  95.  
  96.  
  97. enum {
  98.     FE_INEXACT                    = 0x00000008,                    /* ((long)(8))   */
  99.     FE_DIVBYZERO                = 0x00000010,                    /* ((long)(16))  */
  100.     FE_UNDERFLOW                = 0x00000020,                    /* ((long)(32))  */
  101.     FE_OVERFLOW                    = 0x00000040,                    /* ((long)(64))  */
  102.     FE_INVALID                    = 0x00000080                    /* ((long)(128)) */
  103. };
  104.  
  105. #else
  106. typedef short                             fexcept_t;
  107. typedef short                             fenv_t;
  108.  
  109. enum {
  110.     FE_INVALID                    = 0x0001,                        /* ((short)(1))  */
  111.     FE_UNDERFLOW                = 0x0002,                        /* ((short)(2))  */
  112.     FE_OVERFLOW                    = 0x0004,                        /* ((short)(4))  */
  113.     FE_DIVBYZERO                = 0x0008,                        /* ((short)(8))  */
  114.     FE_INEXACT                    = 0x0010                        /* ((short)(16)) */
  115. };
  116.  
  117. #endif  /* TARGET_RT_MAC_68881 */
  118.  
  119.  
  120. enum {
  121.     FE_TONEAREST                = 0x0000,                        /* ((short)(0))  */
  122.     FE_UPWARD                    = 0x0001,                        /* ((short)(1))  */
  123.     FE_DOWNWARD                    = 0x0002,                        /* ((short)(2))  */
  124.     FE_TOWARDZERO                = 0x0003                        /* ((short)(3))  */
  125. };
  126.  
  127. /*    Definitions of rounding precision macros  (68K only)                    */
  128.  
  129. enum {
  130.     FE_LDBLPREC                    = 0x0000,                        /* ((short)(0))  */
  131.     FE_DBLPREC                    = 0x0001,                        /* ((short)(1))  */
  132.     FE_FLTPREC                    = 0x0002                        /* ((short)(2))  */
  133. };
  134.  
  135. #endif  /* TARGET_CPU_68K */
  136.  
  137. /*    The bitwise OR of all exception macros                                  */
  138.  
  139. #define      FE_ALL_EXCEPT     ( FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID )
  140. /*    Definition of pointer to IEEE default environment object                */
  141. extern fenv_t _FE_DFL_ENV;               /* default environment object        */
  142. #define FE_DFL_ENV &_FE_DFL_ENV          /* pointer to default environment    */
  143.  
  144. /*******************************************************************************
  145. *     The following functions provide access to the exception flags.  The      *
  146. *     "int" input argument can be constructed by bitwise ORs of the exception  *
  147. *     macros: for example: FE_OVERFLOW | FE_INEXACT.                           *
  148. *******************************************************************************/
  149. /*******************************************************************************
  150. *     The function "feclearexcept" clears the supported exceptions represented *
  151. *     by its argument.                                                         *
  152. *******************************************************************************/
  153. EXTERN_API_C( void ) feclearexcept(int excepts);
  154.  
  155.  
  156.  
  157. /*******************************************************************************
  158. *    The function "fegetexcept" stores a representation of the exception       *
  159. *     flags indicated by the argument "excepts" through the pointer argument   *
  160. *     "flagp".                                                                 *
  161. *******************************************************************************/
  162. EXTERN_API_C( void ) fegetexcept(fexcept_t *flagp, int excepts);
  163.  
  164.  
  165.  
  166. /*******************************************************************************
  167. *     The function "feraiseexcept" raises the supported exceptions             *
  168. *     represented by its argument.                                             *
  169. *******************************************************************************/
  170. EXTERN_API_C( void ) feraiseexcept(int excepts);
  171.  
  172.  
  173.  
  174. /*******************************************************************************
  175. *     The function "fesetexcept" sets or clears the exception flags indicated  *
  176. *     by the int argument "excepts" according to the representation in the     *
  177. *     object pointed to by the pointer argument "flagp".  The value of         *
  178. *     "*flagp" must have been set by a previous call to "fegetexcept".         *
  179. *     This function does not raise exceptions; it just sets the state of       *
  180. *     the flags.                                                               *
  181. *******************************************************************************/
  182. EXTERN_API_C( void ) fesetexcept(const fexcept_t *flagp, int excepts);
  183.  
  184.  
  185.  
  186. /*******************************************************************************
  187. *     The function "fetestexcept" determines which of the specified subset of  *
  188. *     the exception flags are currently set.  The argument "excepts" specifies *
  189. *     the exception flags to be queried as a bitwise OR of the exception       *
  190. *     macros.  This function returns the bitwise OR of the exception macros    *
  191. *     corresponding to the currently set exceptions included in "excepts".     *
  192. *******************************************************************************/
  193. EXTERN_API_C( int ) fetestexcept(int excepts);
  194.  
  195.  
  196.  
  197. /*******************************************************************************
  198. *     The following functions provide control of rounding direction modes.     *
  199. *******************************************************************************/
  200. /*******************************************************************************
  201. *     The function "fegetround" returns the value of the rounding direction    *
  202. *     macro which represents the current rounding direction.                   *
  203. *******************************************************************************/
  204. EXTERN_API_C( int ) fegetround(void );
  205.  
  206.  
  207.  
  208. /*******************************************************************************
  209. *     The function "fesetround" establishes the rounding direction represented *
  210. *     by its argument.  It returns nonzero if and only if the argument matches *
  211. *     a rounding direction macro.  If not, the rounding direction is not       *
  212. *     changed.                                                                 *
  213. *******************************************************************************/
  214. EXTERN_API_C( int ) fesetround(int round);
  215.  
  216.  
  217.  
  218. /*******************************************************************************
  219. *    The following functions manage the floating-point environment, exception  *
  220. *    flags and dynamic modes, as one entity.                                   *
  221. *******************************************************************************/
  222. /*******************************************************************************
  223. *     The function "fegetenv" stores the current floating-point environment    *
  224. *     in the object pointed to by its pointer argument "envp".                 *
  225. *******************************************************************************/
  226. EXTERN_API_C( void ) fegetenv(fenv_t *envp);
  227.  
  228.  
  229.  
  230. /*******************************************************************************
  231. *     The function "feholdexcept" saves the current environment in the object  *
  232. *     pointed to by its pointer argument "envp", clears the exception flags,   *
  233. *     and clears floating-point exception enables.  This function supersedes   *
  234. *     the SANE function "procentry", but it does not change the current        *
  235. *     rounding direction mode.                                                 *
  236. *******************************************************************************/
  237. EXTERN_API_C( int ) feholdexcept(fenv_t *envp);
  238.  
  239.  
  240.  
  241. /*******************************************************************************
  242. *     The function "fesetenv" installs the floating-point environment          *
  243. *     environment represented by the object pointed to by its argument         *
  244. *     "envp".  The value of "*envp" must be set by a call to "fegetenv" or     *
  245. *     "feholdexcept", by an implementation-defined macro of type "fenv_t",     *
  246. *     or by the use of the pointer macro FE_DFL_ENV as the argument.           *
  247. *******************************************************************************/
  248. EXTERN_API_C( void ) fesetenv(const fenv_t *envp);
  249.  
  250.  
  251.  
  252. /*******************************************************************************
  253. *     The function "feupdateenv" saves the current exceptions into its         *
  254. *     automatic storage, installs the environment represented through its      *
  255. *     pointer argument "envp", and then re-raises the saved exceptions.        *
  256. *     This function, which supersedes the SANE function "procexit", can be     *
  257. *     used in conjunction with "feholdexcept" to write routines which hide     *
  258. *     spurious exceptions from their callers.                                  *
  259. *******************************************************************************/
  260. EXTERN_API_C( void ) feupdateenv(const fenv_t *envp);
  261.  
  262.  
  263.  
  264. #if TARGET_CPU_68K
  265. /*******************************************************************************
  266. *     The following functions provide control of rounding precision.           *
  267. *     Because the PowerPC does not provide this capability, these functions    *  
  268. *     are available only for the 68K Macintosh.  Rounding precision values     *
  269. *     are defined by the rounding precision macros.  These functions are       *
  270. *     equivalent to the SANE functions getprecision and setprecision.          *
  271. *******************************************************************************/
  272. EXTERN_API_C( int ) fegetprec(void );
  273.  
  274. EXTERN_API_C( int ) fesetprec(int precision);
  275.  
  276. #endif  /* TARGET_CPU_68K */
  277.  
  278.  
  279.  
  280. #if PRAGMA_STRUCT_ALIGN
  281.     #pragma options align=reset
  282. #elif PRAGMA_STRUCT_PACKPUSH
  283.     #pragma pack(pop)
  284. #elif PRAGMA_STRUCT_PACK
  285.     #pragma pack()
  286. #endif
  287.  
  288. #ifdef PRAGMA_IMPORT_OFF
  289. #pragma import off
  290. #elif PRAGMA_IMPORT
  291. #pragma import reset
  292. #endif
  293.  
  294. #ifdef __cplusplus
  295. }
  296. #endif
  297.  
  298. #endif /* __FENV__ */
  299.  
  300.